package com.mlxg.untils.file;

import java.util.Arrays;
import java.util.List;

/**
 * 媒体类型工具类
 *
 * @author ruoyi
 */
public class MimeTypeUtils {
    public static final String IMAGE_PNG = "image/png";

    public static final String IMAGE_JPG = "image/jpg";

    public static final String IMAGE_JPEG = "image/jpeg";

    public static final String IMAGE_BMP = "image/bmp";

    public static final String IMAGE_GIF = "image/gif";

    public static final String APPLICATION_PDF = "application/pdf";
    public static final String MP4 = "video/mp4";

    public static final String AVI = "video/x-msvideo";

    public static final String RMVB = "application/vnd.rn-realmedia-vbr";

    public static final String MOV = "video/quicktime";
    public static final String DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    public static final String ZIP = "application/zip";
    public static final String DOC = "application/msword";
    public static final String M4V = "video/x-m4v";
    public static final String TIF = "image/tiff";

    public static final List<String> IMAGE_EXTENSION = Arrays.asList("bmp", "gif", "jpg", "jpeg", "png", "pdf");

    public static final List<String> FLASH_EXTENSION = Arrays.asList("swf", "flv");

    public static final List<String> MEDIA_EXTENSION = Arrays.asList("swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
            "asf", "rm", "rmvb");

    public static final List<String> VIDEO_EXTENSION = Arrays.asList("mp4", "avi", "rmvb");

    public static final List<String> DEFAULT_ALLOWED_EXTENSION = Arrays.asList( // 图片
            "bmp", "gif", "jpg", "jpeg", "png","tif",
            // word excel powerpoint
            "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
            // 压缩文件
            "rar", "zip", "gz", "bz2",
            // 视频格式
            "mp4", "avi", "rmvb", "mov","m4v",
            // pdf
            "pdf");

    public static final List<String> DEFAULT_ALLOWED_EXTENSIONS = Arrays.asList(
            // 视频格式
            "mp4", "avi", "rmvb", "mov");

    public static String getExtension(String prefix) {
        switch (prefix) {
            case IMAGE_PNG:
                return "png";
            case IMAGE_JPG:
                return "jpg";
            case IMAGE_JPEG:
                return "jpeg";
            case IMAGE_BMP:
                return "bmp";
            case IMAGE_GIF:
                return "gif";
            case APPLICATION_PDF:
                return "pdf";
            default:
                return "";
        }
    }

    public static String getContextType(String prefix) {
        switch (prefix) {
            case "png":
                return IMAGE_PNG;
            case "jpg":
                return IMAGE_JPG;
            case "jpeg":
                return IMAGE_JPEG;
            case "bmp":
                return IMAGE_BMP;
            case "gif":
                return IMAGE_GIF;
            case "pdf":
                return APPLICATION_PDF;
            case "mp4":
                return MP4;
            case "avi":
                return AVI;
            case "rmvb":
                return RMVB;
            case "mov":
                return MOV;
            case "docx":
                return DOCX;
            case "zip":
                return ZIP;
            case "doc":
                return DOC;
            case "m4v":
                return M4V;
            case "tif":
                return TIF;
            default:
                return "";
        }
    }
}
